/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html, body {
    height: 100vh;
    font-family: Arial, sans-serif;
    background-color: #ece5dd;
    /* Center the page content and disable page scroll */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Chat container occupies 2/3 of viewport height and width, centered */
#chat-container {
    width: 66.66vw;
    height: 66.66vh;
    /* Remove extra margin-top so container is truly centered */
    /* margin: auto; */
    margin-top: 0%;
    display: flex;
    border: 1px solid #ccc;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

/* Sidebar for contact list */
#sidebar {
    width: 30%;
    border-right: 1px solid #ccc;
    padding: 10px;
    background: #f7f7f7;
    display: flex;
    flex-direction: column;
}

#sidebar input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin-bottom: 10px;
}

#add-friend {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

/* 动态好友列表容器：占据剩余空间且可滚动 */
#contact-list-container {
    flex: 1;
    overflow-y: auto;
}

/* 隐藏滚动条 */
#contact-list-container::-webkit-scrollbar {
    display: none;
}

/* 好友列表内部 */
.contact-list {
    display: flex;
    flex-direction: column;
    gap: 0px;
}

/* 联系人样式保持不变 */
.contact {
    position: relative;
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.contact:hover {
    background-color: #eaeaea;
}
.contact-name {
    font-weight: bold;
}
.contact-msg {
    color: #666;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.contact-time {
    color: #999;
    font-size: 0.8em;
    position: absolute;
    right: 10px;
    top: 10px;
    text-align: right;
}

.contact.active {
    background-color: #e8e8e8;
    border-left: 3px solid #009688;
}

#sidebar-footer {
    margin-top: auto; /* 自动填充剩余空间，推到最底部 */
    padding-top: 10px;
}
.logout-btn {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: #9b59b6;
    color: #fff;
    text-align: center;
    text-decoration: none;
    border-radius: 4px;
}


/* Main chat window */
#chat-window {
    width: 70%;
    display: flex;
    flex-direction: column;
}

#chat-header {
    padding: 10px;
    background: #f1f1f1;
    border-bottom: 1px solid #ccc;
}

#chat-name {
    font-size: 1.2em;
}

#messages {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Hide scrollbar for Webkit */
}
#messages::-webkit-scrollbar {
    display: none;
}
/* Also for Firefox */
#messages {
    scrollbar-width: none;
}

/* Message styles */
.message {
    padding: 10px;
    border-radius: 8px;
    max-width: 70%;
    word-break: break-word;
}

.sent {
    align-self: flex-end;
    background-color: #dcf8c6;
    text-align: right;
}

.received {
    align-self: flex-start;
    background-color: #f1f0f0;
    text-align: left;
}

/* Message input area */
#message-input {
    display: flex;
    padding: 10px;
    border-top: 1px solid #ccc;
    background: #f9f9f9;
    align-items: flex-end;
}

/* Use a textarea for multi-line automatic resizing */
#message-text {
    flex: 1;
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 10px;
    font-family: inherit;
    /* Start with one line height */
    min-height: 1.5em;
    /* Limit height to 1/5 of chat container height */
    max-height: calc(66.66vh / 5);
    /* Let JavaScript control the height dynamically */
    height: auto;
    overflow-y: auto;
    resize: none;
}

/* Hide scrollbar for message input (Webkit and Firefox) */
#message-text::-webkit-scrollbar {
    width: 0;
    background: transparent;
}
#message-text {
    scrollbar-width: none;
}

/* Send button styles */
#send-btn {
    margin-left: 10px;
    padding: 10px 20px;
    background-color: #009688;
    border: none;
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
}
#send-btn:hover {
    background-color: #00796b;
}

.unread-badge {
    width: 8px;
    height: 8px;
    background-color: #f00;
    border-radius: 50%;
    position: absolute;
    right: 10px;
    top: 10px;
}